package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("增加图书!");
        System.out.print("请输入书名:");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        int curSize=bookList.getUsedSize();
        for (int i = 0; i < curSize; i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                System.out.println("已经存在该图书，不能在添加!");
                return;
            }
        }
        System.out.print("请输入作者:");
        String author=scanner.nextLine();
        System.out.print("请输入价格:");
        int price=scanner.nextInt();
        scanner.nextLine();
        System.out.print("请输入类型:");
        String type=scanner.nextLine();
        //开始往booklist里面添加图书
        Book book=new Book(name,author,price,type);
        bookList.setBook(book);
        //修改usedsize的值
        bookList.setUsedSize(curSize+1);
        System.out.println("添加成功");
    }
}
